package com.zige.zige.activity;

import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.nineoldandroids.view.ViewHelper;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;
import com.zige.zige.LittleZebraApplication;
import com.zige.zige.R;
import com.zige.zige.activity.videoplay.ActivityVideodetailActivity;
import com.zige.zige.activity.videoplay.MenuVideodetailActivity;
import com.zige.zige.activity.videoplay.PlayerAvtivity;
import com.zige.zige.activity.videoplay.VideodetailActivity;
import com.zige.zige.bean.HomeBean;
import com.zige.zige.bean.Menubean;
import com.zige.zige.bj_vr.BJVrPlayActivity;
import com.zige.zige.constants.UrlConsts;
import com.zige.zige.dialog.EvaluationAppDialog;
import com.zige.zige.dialog.UpdateAppDialog;
import com.zige.zige.operationgudie.MainOperateDialog;
import com.zige.zige.pojo.UserInfo;
import com.zige.zige.pojo.VideoInfo;
import com.zige.zige.task.PostRequestTask;
import com.zige.zige.task.TaskExecutor;
import com.zige.zige.utils.ACache;
import com.zige.zige.utils.NetworkUtils;
import com.zige.zige.utils.SharedPreferencesUtils;
import com.zige.zige.utils.StringUtils;
import com.zige.zige.utils.SystemUtils;
import com.zige.zige.utils.ToastUtils;
import com.zige.zige.utils.VolleyImageUtils;
import com.zige.zige.view.CircleImageView;
import com.zige.zige.view.DragLayout;
import com.zige.zige.view.MainContentLayout;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Fei on 2016/2/27.
 */
public class HomedActivity extends BaseActivity implements View.OnClickListener {


    private UserInfo userInfo;
    private String loginAccount;
    private String loginPassword;
    private long firstime = 0;
    private int dayTheme;
    private int isDays;

    /***
     * Menu
     */
    private DragLayout mMenu;
    private MainContentLayout mMainContent;
    private RelativeLayout lay_menu;
    private CircleImageView head_img;
    private ImageView image_head_bg;
    private TextView tv_login;
    private ImageView img_menu;

    private RelativeLayout lay_personinfo;
    private RelativeLayout lay_setcenter;
    private RelativeLayout lay_userfeedback;
    private LinearLayout lay_title_to;
    private ListView listview_menu;
    private menuListAdapter adapter;

    /**
     * 主页
     */
    private TextView video_title;//视频标题
    private TextView video_content;//视频详情
    private ImageView bg_video, imag_menu_round;//视频分类标志
    private ImageView image_viceo_play;//声音播放
    private ViewPager viewPager;
    private MyVPAdapter myVPAdapter;
    private LinearLayout lay_content;
    private RelativeLayout lay_viewpager;


    private Context context;
    private List<HomeBean.ActivityListEntity> activityListEntities = new ArrayList<>();
    private List<HomeBean.VideoListEntity> videoListEntities = new ArrayList<>();
    private List<HomeBean.MenuListEntity> menuListEntities = new ArrayList<>();
    private ArrayList<VideoInfo> mList = new ArrayList<>();
    private ArrayList<Menubean> mMenuList = new ArrayList<>();
    private HomeBean mHomeBean;


    private List<Fragment> fragments = new ArrayList<>();    //播放声音
    private MediaPlayer voicePlayer = new MediaPlayer();

    /****
     * 初始化底部按钮
     */
    private Button btn_first, btn_second, btn_third;
    private View view_btn1, view_btn2, view_btn3;
    private LinearLayout lay_btn1, lay_btn2, lay_btn3;
    private HorizontalScrollView scrollView_to;

    private int textWhite;
    private int textBlack;
    private int lineBlue;
    private int lineWhite;

    private int width;

    //----是否更新App的参数//
    private String updateAppUrl;

    private ACache acache;

    /**
     * web菜单
     */


    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    initViewPager();
                    break;
                case 5:
                    showLoadingDialog();
                    break;
                case 6:
                    closeLoadingDialog();
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        setContentView(R.layout.activity_homed);
        context = this;
        acache = ACache.get(context);
        userInfo = application.getUserInfo();
        Log.e("wu", "eee   " + SystemUtils.getDeviceKey(this));
        Log.e("wu", "oooo    " + JPushInterface.getRegistrationID(this));
        application.getMenubean();

        showDialog();
        shaow();
        first();
        setHistory();
        initView();
        initTab();
        if (mHomeBean != null) {
            getData(mHomeBean);
        } else {
            if (NetworkUtils.isNetworkAvailable(context)) {
                mHomeBean = LittleZebraApplication.getInstance().getHomeBean();
                sendRequest();
            } else {
                showErrorDialog("当前网络异常");
                startActivity(new Intent(HomedActivity.this, NetErrorActivity.class));
            }
        }
        isDays = 0;
        initColor(isDays);
        setDaybg(isDays);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMenu.setBackgroundResource(R.drawable.evening_home_menu_bg);
        refresh();
    }

    private void refresh() {

        if (application.isLogin()) {
            if (application.getUserInfo().childName != null || application.getUserInfo().childName != "") {
                tv_login.setText(application.getUserInfo().childName);
            } else {
                tv_login.setText("");
            }
            if (StringUtils.isEmpty(application.getUserInfo().headPortraitUrl)) {
                head_img.setVisibility(View.GONE);
                image_head_bg.setVisibility(View.VISIBLE);
            } else {
                head_img.setVisibility(View.VISIBLE);
                image_head_bg.setVisibility(View.GONE);
                VolleyImageUtils.displayImage(application.getUserInfo().headPortraitUrl, head_img, context);
                head_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(HomedActivity.this, PersonalInformationActivity.class));
                    }
                });
            }

        } else {
            tv_login.setText("登录");
            head_img.setVisibility(View.GONE);
            image_head_bg.setVisibility(View.VISIBLE);

        }

        if (application.getMainNeedRefresh()) {
            if (selectBtn == 0) {
                if (NetworkUtils.isNetworkAvailable(context)) {
                    sendRequest();
                } else {
                    showErrorDialog("当前网络异常");
                }
            } else if (selectBtn == 1) {
                if (NetworkUtils.isNetworkAvailable(context)) {
                    getHistoryDate("1");
                } else {
                    showErrorDialog("当前网络异常");
                }
            } else if (selectBtn == 2) {
                if (NetworkUtils.isNetworkAvailable(context)) {
                    getHistoryDate("2");
                } else {
                    showErrorDialog("当前网络异常");
                }
            }
            application.setMainNeedRefresh(false);
        }
    }

    private void updateAPP(int updateAppVersion, String updateAppUrl) {
        boolean ishowed = (boolean) SharedPreferencesUtils.getValue(HomedActivity.this, SharedPreferencesUtils.update_appprompt, false);
        if (updateAppVersion == 1 || updateAppVersion == 2) {
            if (!ishowed) {
                UpdateAppDialog dialog = new UpdateAppDialog();
                Bundle bundle = new Bundle();
                bundle.putInt("UpdateAppVersion", updateAppVersion);
                bundle.putString("updateAppUrl", updateAppUrl);
                dialog.setArguments(bundle);
                dialog.show(getFragmentManager(), "dialog");
            }
        }
    }


    private void initView() {
        //初始化菜单控件
        mMenu = serchViewById(R.id.id_menu_home);
        mMenu.setOnLayoutDragingListener(new DragLayout.OnLayoutDragingListener() {

            @Override
            public void onOpen() {

            }

            @Override
            public void onDraging(float percent) {

//                ViewHelper.setAlpha(img_menu, 1 - percent);
            }

            @Override
            public void onClose() {

            }
        });

        mMainContent = serchViewById(R.id.mainContent);
        mMainContent.setDragLayout(mMenu);
        lay_menu = serchViewById(R.id.lay_menu);
        lay_menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMenu.open();
            }
        });
        img_menu = serchViewById(R.id.img_menu);
        lay_personinfo = serchViewById(R.id.lay_personinfo);
        lay_personinfo.setOnClickListener(this);
        lay_setcenter = serchViewById(R.id.lay_setcenter);
        lay_setcenter.setOnClickListener(this);
        lay_userfeedback = serchViewById(R.id.lay_userfeedback);
        lay_userfeedback.setOnClickListener(this);

        image_viceo_play = serchViewById(R.id.image_voice_play);
        image_viceo_play.setOnClickListener(this);
        imag_menu_round = serchViewById(R.id.imag_menu_round);

        listview_menu = serchViewById(R.id.menu_listView);
        adapter = new menuListAdapter();
        listview_menu.setAdapter(adapter);
        listview_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });

        /***
         * 初始化主页控件
         */
        viewPager = serchViewById(R.id.home_viewpager);
        video_title = serchViewById(R.id.tv_video_title);
        video_content = serchViewById(R.id.tv_video_content);
        video_content.setOnClickListener(this);
        bg_video = serchViewById(R.id.bg_video_select);
        lay_content = serchViewById(R.id.lay_content);
        lay_viewpager = serchViewById(R.id.lay_viewpager);

        head_img = serchViewById(R.id.head_img_bg);
        image_head_bg = serchViewById(R.id.image_bg);
        tv_login = serchViewById(R.id.tv_login);
        head_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (application.isLogin()) {
                    startActivity(new Intent(HomedActivity.this, PersonalInformationActivity.class));
                } else {
                    startActivityForResult(new Intent(HomedActivity.this, RegisterActivity.class), ACTIVITY_REGISTER);
                }
                mMenu.close();
            }
        });

        image_head_bg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (application.isLogin()) {
                    startActivity(new Intent(HomedActivity.this, PersonalInformationActivity.class));
                } else {
                    startActivityForResult(new Intent(HomedActivity.this, RegisterActivity.class), ACTIVITY_REGISTER);
                }
                mMenu.close();
            }
        });

        tv_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMenu.close();
                if (application.isLogin()) {
                    startActivity(new Intent(HomedActivity.this, PersonalInformationActivity.class));
                } else {
                    startActivityForResult(new Intent(HomedActivity.this, RegisterActivity.class), ACTIVITY_REGISTER);
                }
            }
        });
    }

    private void setDaybg(int day) {
        if (day == 0) {
            mMenu.setBackgroundResource(R.drawable.whiteday_home_menubg);
            img_menu.setImageResource(R.drawable.whiteday_menu_bg);
            video_title.setTextColor(getResources().getColor(R.color.color_777777));
            video_content.setTextColor(getResources().getColor(R.color.color_777777));
            scrollView_to.setBackgroundColor(getResources().getColor(R.color.white));
            lay_content.setBackgroundColor(getResources().getColor(R.color.activity_bg));
        } else if (day == 1) {
            mMenu.setBackgroundResource(R.drawable.evening_home_menu_bg);
            img_menu.setImageResource(R.drawable.evening_menu_bg);
            video_title.setTextColor(getResources().getColor(R.color.white));
            video_content.setTextColor(getResources().getColor(R.color.white));
            scrollView_to.setBackgroundColor(getResources().getColor(R.color.color_1A263B));
            lay_content.setBackgroundResource(R.drawable.evening_home_bg);
        }
    }

    private void initColor(int day) {
        if (day == 0) {
            textWhite = getResources().getColor(R.color.m_btn_text);
            textBlack = getResources().getColor(R.color.m_btn_text_select);
            lineBlue = getResources().getColor(R.color.m_view_bg_select);
            lineWhite = getResources().getColor(R.color.line_gory);
        } else if (day == 1) {
            textWhite = getResources().getColor(R.color.m_btn_text);
            textBlack = getResources().getColor(R.color.white);
            lineBlue = getResources().getColor(R.color.view_bg);
            lineWhite = getResources().getColor(R.color.color_253444);
        }

    }


    /**
     * 初始化tablayout
     */
    private void initTab() {
        scrollView_to = serchViewById(R.id.scrollView_to);
        scrollView_to.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    mMenu.close();
                }
            }
        });

        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        width = metric.widthPixels; // 屏幕宽度（像素）;

        view_btn1 = serchViewById(R.id.view_btn1);
        view_btn2 = serchViewById(R.id.view_btn2);
        view_btn3 = serchViewById(R.id.view_btn3);

        btn_first = serchViewById(R.id.btn_first);
        btn_first.setOnClickListener(new BtnSelectListener());
        btn_second = serchViewById(R.id.btn_second);
        btn_second.setOnClickListener(new BtnSelectListener());
        btn_third = serchViewById(R.id.btn_third);
        btn_third.setOnClickListener(new BtnSelectListener());

        lay_btn1 = serchViewById(R.id.lay_btn1);
        lay_btn2 = serchViewById(R.id.lay_btn2);
        lay_btn3 = serchViewById(R.id.lay_btn3);
        ViewGroup.LayoutParams params = lay_btn1.getLayoutParams();
        params.width = width / 2;
        lay_btn2.getLayoutParams().width = width / 2;
        lay_btn3.getLayoutParams().width = width / 2;
        btn_first.setText("今天");
        btn_second.setText("昨天");
        btn_third.setText("前天");

        if (isDays == 0) {
            view_btn1.setBackgroundColor(getResources().getColor(R.color.m_view_bg_select));
            btn_first.setTextColor(getResources().getColor(R.color.black));
        } else if (isDays == 1) {
            view_btn1.setBackgroundColor(getResources().getColor(R.color.view_bg));
            btn_first.setTextColor(getResources().getColor(R.color.white));


        }
    }

    private void shaow() {
        String show = (String) SharedPreferencesUtils.getValue(HomedActivity.this, "showCommentAlert", "0");
        boolean isShow = (boolean) SharedPreferencesUtils.getValue(HomedActivity.this, "showCommentAlert", true);
        if (show.equals("1") && isShow) {
            EvaluationAppDialog dialog = new EvaluationAppDialog();
            dialog.show(getSupportFragmentManager(), "show");


        }
    }


    /**
     * 这是变色龙
     */
    private boolean isShowed;
    private int selectBtn = 0;

    class BtnSelectListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.push_right_in);
            switch (v.getId()) {
                case R.id.btn_first:
                    selectBtn = 0;
                    setHistory();
                    changeColor(textBlack, textWhite, textWhite, lineBlue, lineWhite, lineWhite);
                    view_btn1.startAnimation(animation);

                    isShowed = false;
                    if (NetworkUtils.isNetworkAvailable(context)) {
                        sendRequest();

                    } else {
                        showErrorDialog("当前网络异常");
                    }
                    break;
                case R.id.btn_second:
                    selectBtn = 1;
                    changeColor(textWhite, textBlack, textWhite, lineWhite, lineBlue, lineWhite);
                    view_btn2.startAnimation(animation);
                    isShowed = !btn_second.isSelected();
                    if (isShowed) {
                        btn_second.setSelected(true);
                    } else {
                        btn_second.setSelected(false);
                    }
                    if (NetworkUtils.isNetworkAvailable(context)) {
                        getHistoryDate("1");
                    } else {
                        showErrorDialog("当前网络异常");
                    }
                    break;
                case R.id.btn_third:
                    selectBtn = 3;
                    changeColor(textWhite, textWhite, textBlack, lineWhite, lineWhite, lineBlue);
                    view_btn3.startAnimation(animation);
                    isShowed = false;
                    if (NetworkUtils.isNetworkAvailable(context)) {
                        getHistoryDate("2");
                    } else {
                        showErrorDialog("当前网络异常");
                    }
                    break;
            }
        }
    }

    private void changeColor(int text1, int text2, int text3, int line1, int line2, int line3) {
        btn_first.setTextColor(text1);
        btn_second.setTextColor(text2);
        btn_third.setTextColor(text3);
        view_btn1.setBackgroundColor(line1);
        view_btn2.setBackgroundColor(line2);
        view_btn3.setBackgroundColor(line3);
    }


    boolean isVoicePlay;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lay_title_to:
//                if (mMenu.isOpen) {
//                    mMenu.closeMenu();
//                } else {
                mMenu.close();
                lay_title_to.setOnClickListener(null);
//                }
                break;
            case R.id.tv_login:
                if (voicePlayer != null) {
                    voicePlayer.pause();
                }
                startActivityForResult(new Intent(HomedActivity.this, RegisterActivity.class), ACTIVITY_REGISTER);
                overridePendingTransition(R.anim.l2r_in, R.anim.l2r_out);
                mMenu.close();
                break;
            case R.id.lay_personinfo:
                if (voicePlayer != null) {
                    voicePlayer.pause();
                }
                if (application.isLogin()) {
                    startActivity(new Intent(context, PersonalInformationActivity.class));
                    overridePendingTransition(R.anim.l2r_in, R.anim.l2r_out);
                } else {
                    userLogin();

                }
                mMenu.close();
                break;
            case R.id.lay_setcenter:
                if (voicePlayer != null) {
                    voicePlayer.pause();
                }
                mMenu.close();
                startActivity(new Intent(context, SettingCenterActivity.class));
                overridePendingTransition(R.anim.l2r_in, R.anim.l2r_out);
                break;
            case R.id.lay_userfeedback:
                if (voicePlayer != null) {
                    voicePlayer.pause();
                }
                mMenu.close();
                startActivity(new Intent(context, UserFeedbackActivity.class));
                overridePendingTransition(R.anim.l2r_in, R.anim.l2r_out);
                break;
            case R.id.image_voice_play:
                isVoicePlay = !image_viceo_play.isSelected();
                if (isVoicePlay) {
                    if (dayTheme == 0) {
                        image_viceo_play.setImageResource(R.drawable.whiteday_bg_voice_play_no);
                    } else {
                        image_viceo_play.setImageResource(R.drawable.evening_bg_voice_play_no);
                    }
                    image_viceo_play.setSelected(true);
                    if (voicePlayer != null) {
                        voicePlayer.pause();
                        Log.e("wu","55555"+isVoicePlay);
                    }
                    SharedPreferencesUtils.saveValue(HomedActivity.this, SharedPreferencesUtils.isplayvoice, true);
                } else {
                    if (dayTheme == 0) {
                        image_viceo_play.setImageResource(R.drawable.whiteday_bg_voice_play);
                    } else {
                        image_viceo_play.setImageResource(R.drawable.evening_bg_voice_play);
                    }

                    image_viceo_play.setSelected(false);
                    SharedPreferencesUtils.saveValue(HomedActivity.this, SharedPreferencesUtils.isplayvoice, isVoicePlay);
                    if (voicePlayer != null) {
                        voicePlayer.start();
                        Log.e("wu","  rrrr"+isVoicePlay);
                    }
                }
                break;
            case R.id.tv_video_content:
                if (voicePlayer != null) {
                    voicePlayer.pause();
                }
                if (mList.size() > 0) {
                    if (mList.get(viewPager.getCurrentItem()).getType() == 0) {
                        if (mList.get(viewPager.getCurrentItem()).getActivityType() == 0) {
                            String activityName = mList.get(viewPager.getCurrentItem()).getActivityName();
                            String activityUrl = mList.get(viewPager.getCurrentItem()).getPageUrl();
                            Intent intent = new Intent(context, ActivityVideoWebActivirt.class);
                            intent.putExtra("activityName", activityName);
                            intent.putExtra("activityUrl", activityUrl);
                            startActivity(intent);
                        } else if (mList.get(viewPager.getCurrentItem()).getActivityType() == 1) {
                            Intent intent = new Intent(context, ActivityVideodetailActivity.class);
                            intent.putExtra("videoId", mList.get(viewPager.getCurrentItem()).getId());
                            startActivity(intent);
                        }
                    } else if (mList.get(viewPager.getCurrentItem()).getType() == 1) {
                        if (mList.get(viewPager.getCurrentItem()).getVideoType() == 1) {
                            Intent intent = new Intent(HomedActivity.this, VideodetailActivity.class);
                            intent.putExtra("position", viewPager.getCurrentItem());
                            intent.putExtra("playList", mList);
                            intent.putExtra("mSize", mSize);
                            startActivity(intent);
                        } else if (mList.get(viewPager.getCurrentItem()).getVideoType() == 0) {
                            Intent intent = new Intent(HomedActivity.this, VideodetailActivity.class);
                            intent.putExtra("position", viewPager.getCurrentItem());
                            intent.putExtra("playList", mList);
                            intent.putExtra("mSize", mSize);
                            startActivity(intent);
                        }

                    }
                }
//                }

                break;
        }
    }


    private void userLogin() {
        startActivityForResult(new Intent(HomedActivity.this, RegisterActivity.class), ACTIVITY_REGISTER);
        overridePendingTransition(R.anim.l2r_in, R.anim.l2r_out);
        mMenu.close();
    }

    private boolean isSelected = true;

    private void initViewPager() {
        setvideoText(0);
        if (myVPAdapter == null) {
//            myVPAdapter = null;
//        }
            myVPAdapter = new MyVPAdapter(mList);
            myVPAdapter.notifyDataSetChanged();
            viewPager.setAdapter(myVPAdapter);
            viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    setvideoText(position);
                    if (position == 0) {
                        mMenu.setDrag(true);
                    } else {
                        mMenu.setDrag(false);
                    }

                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    if (state == 1) {
                        isSelected = false;
                    } else if (state == 2) {
                        isSelected = true;
                    }

                }
            });
            viewPager.setOffscreenPageLimit(5);
            viewPager.setCurrentItem(0);
            viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));
            lay_viewpager.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    mMenu.close();
                    return viewPager.dispatchTouchEvent(event);
                }
            });
        } else {
            myVPAdapter.setVideoList(mList);
        }

        myVPAdapter.notifyDataSetChanged();
        viewPager.setCurrentItem(0);
    }

    private int dayFirst, hisFirst;

    class MyVPAdapter extends PagerAdapter {
        private ArrayList<VideoInfo> videoList;

        public void setVideoList(ArrayList<VideoInfo> datas) {
            this.videoList = datas;
        }

        public MyVPAdapter(ArrayList<VideoInfo> datas) {
            videoList = datas;
        }

        @Override
        public int getCount() {
            return videoList.size();
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return (view == object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, final int position) {
            View view = LayoutInflater.from(HomedActivity.this).inflate(R.layout.home_item_fragment, null);
            ImageView show_video_img = (ImageView) view.findViewById(R.id.home_item_video_pic);
            ImageView playVideo_img = (ImageView) view.findViewById(R.id.play_img);
            ImageView img_home_item_bg = (ImageView) view.findViewById(R.id.img_home_item_bg);
            int[] type = {1, 2, 3, 4, 5};
            int textColorType = (int) (Math.random() * type.length) + 1;
            switch (textColorType) {
                case 1:
                    show_video_img.setImageResource(R.drawable.home_item_select_blue);
                    break;
                case 2:
                    show_video_img.setImageResource(R.drawable.home_item_select_orange);
                    break;
                case 3:
                    show_video_img.setImageResource(R.drawable.home_item_select_pink);
                    break;
                case 4:
                    show_video_img.setImageResource(R.drawable.home_item_select_yellow);
                    break;
                case 5:
                    show_video_img.setImageResource(R.drawable.home_item_select_darkblue);
                    break;
                default:
                    show_video_img.setImageResource(R.drawable.home_item_select_darkblue);
                    break;
            }
            if (dayTheme == 0) {
                img_home_item_bg.setImageResource(R.drawable.item_bg);
            } else {
                img_home_item_bg.setImageResource(R.drawable.home_item_bg_evening);
            }
//            if (textColorType == 1) {
//                    show_video_img.setImageResource(R.drawable.home_item_select_blue);
//            } else if (textColorType == 2) {
//                    show_video_img.setImageResource(R.drawable.home_item_select_orange);
//            } else if (textColorType == 3) {
//                show_video_img.setBackgroundColor(getResources().getColor(R.color.color_FE7A9F));
//            } else if (textColorType == 4) {
//                show_video_img.setBackgroundColor(getResources().getColor(R.color.color_FAB615));
//            } else if (textColorType == 5) {
//                show_video_img.setBackgroundColor(getResources().getColor(R.color.color_0091EA));
//            } else {
//                show_video_img.setBackgroundColor(getResources().getColor(R.color.color_0091EA));
//            }
            show_video_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mMenu.close();
                }
            });
            if (videoList.get(position).getType() == 0) {
                Picasso.with(HomedActivity.this).load(videoList.get(position).getPicUrl()).into(show_video_img);
            } else {
                Picasso.with(HomedActivity.this).load(videoList.get(position).getVideoPicUrl()).into(show_video_img);
            }
            if (videoList.get(position).getType() == 0) {
                if (videoList.get(position).getActivityType() == 0) {
                    playVideo_img.setVisibility(View.GONE);
                    show_video_img.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (voicePlayer != null) {
                                voicePlayer.pause();
                            }
                            String activityName = videoList.get(position).getActivityName();
                            String activityUrl = videoList.get(position).getPageUrl();
                            Intent intent = new Intent(HomedActivity.this, ActivityVideoWebActivirt.class);
                            intent.putExtra("activityName", activityName);
                            intent.putExtra("activityUrl", activityUrl);
                            startActivity(intent);
                        }
                    });
                } else if (videoList.get(position).getActivityType() == 1) {
                    playVideo_img.setImageResource(R.drawable.vr_video_play);
                    show_video_img.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (voicePlayer != null) {
                                voicePlayer.pause();
                            }
                            Intent intent = new Intent(HomedActivity.this, BJVrPlayActivity.class);
                            intent.putExtra("position", position);
                            intent.putExtra("videoId", videoList.get(position).getId());
                            intent.putExtra("playList", videoList);
                            startActivity(intent);
                        }

                    });
                }
            } else if (videoList.get(position).getType() == 1) {
                if (videoList.get(position).getVideoType() == 1) {
                    playVideo_img.setImageResource(R.drawable.vr_video_play);
                    show_video_img.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (voicePlayer != null) {
                                voicePlayer.pause();
                            }
                            Intent intent = new Intent(HomedActivity.this, BJVrPlayActivity.class);
                            intent.putExtra("position", position);
                            intent.putExtra("playList", videoList);
                            startActivity(intent);
                        }

                    });
                } else if (videoList.get(position).getVideoType() == 0) {
                    show_video_img.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (voicePlayer != null) {
                                voicePlayer.pause();
                            }
                            Intent intent = new Intent(HomedActivity.this, PlayerAvtivity.class);
                            intent.putExtra("position", position);
                            intent.putExtra("playList", videoList);
                            startActivity(intent);
                        }
                    });
                }
            }
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            View view = (View) object;
            container.removeView(view);
        }
    }


    private void first() {
        boolean isfirst = (boolean) SharedPreferencesUtils.getValue(this, SharedPreferencesUtils.first_enter, true);
        //判断程序与第几次运行，如果是第一次运行则跳转到引导页面
        if (isfirst) {
            hisFirst = 1;
            SharedPreferencesUtils.saveValue(this, SharedPreferencesUtils.first_enter, false);
        } else {
            hisFirst = 0;
        }
    }

    private void setHistory() {
        boolean isdayFirst = (boolean) SharedPreferencesUtils.getValue(this, SharedPreferencesUtils.dayFirst, false);
        if (isdayFirst) {
            dayFirst = 1;
            SharedPreferencesUtils.saveValue(this, SharedPreferencesUtils.dayFirst, false);
        } else {
            dayFirst = 1;
        }
    }


    private void showDialog() {
        boolean isShowed = (boolean) SharedPreferencesUtils.getValue(this, SharedPreferencesUtils.main_registe_operate_guide, false);
        if (!isShowed) {
            MainOperateDialog dialog = new MainOperateDialog();
            dialog.show(getSupportFragmentManager(), "show");
        }

    }


    /**
     * 开机启动获取数据
     */
    private void sendRequest() {
        mList.clear();
        fragments.clear();
        closeLoadingDialog();
        final String appVersion = SystemUtils.getVersionName(this).trim();
        String platformType = "android";
        String loginType = "0";
        String userName, password;
        if (application.isLogin()) {
            userName = application.getUserInfo().phoneNumber;
            password = application.getUserInfo().userPassword;
        } else {
            userName = "";
            password = "";
        }
        String devicedId = SystemUtils.getDeviceKey(this).trim();
        String pushKey = JPushInterface.getRegistrationID(this);
        class homeCallBack extends Callback<HomeBean> {
            @Override
            public void onBefore(Request request) {
                super.onBefore(request);
                showLoadingDialog();
            }

            @Override
            public HomeBean parseNetworkResponse(Response response) throws IOException {
                String string = response.body().string();
                closeLoadingDialog();
                Log.e("wo", "主页    " + string);
                HomeBean homeBean = new Gson().fromJson(string, HomeBean.class);
                return homeBean;
            }

            @Override
            public void onError(Request request, Exception e) {
            }

            @Override
            public void onResponse(HomeBean response) {
                closeLoadingDialog();
                Log.e("wu", "666666");
                mHomeBean = response;

                activityListEntities.clear();
                videoListEntities.clear();
                menuListEntities.clear();
                for (HomeBean.ActivityListEntity activityListEntity : response.getActivityList()) {
                    activityListEntities.add(activityListEntity);
                }
                for (HomeBean.VideoListEntity videoListEntity : response.getVideoList()) {
                    videoListEntities.add(videoListEntity);
                }
                if (response.getMenuList() != null) {
                    for (HomeBean.MenuListEntity menuListEntity : response.getMenuList()) {
                        menuListEntities.add(menuListEntity);
                    }
                }

                if (mHomeBean.getCode().equalsIgnoreCase("0000")) {
                    updateAPP(mHomeBean.getUpdateFlag(), mHomeBean.getupdateUrl());
                    if (mHomeBean.getShowReddot() != null) {
                        if (mHomeBean.getShowReddot().equals("1")) {
                            imag_menu_round.setVisibility(View.VISIBLE);
                        } else {
                            imag_menu_round.setVisibility(View.GONE);
                        }
                    }

                    dayTheme = mHomeBean.getDayTheme();
                    initColor(dayTheme);
                    setDaybg(dayTheme);
                    if (dayTheme == 0) {
                        image_viceo_play.setImageResource(R.drawable.whiteday_bg_voice_play);
                        view_btn1.setBackgroundColor(getResources().getColor(R.color.m_view_bg_select));
                        btn_first.setTextColor(getResources().getColor(R.color.black));
                    } else if (dayTheme == 1) {
                        view_btn2.setBackgroundColor(getResources().getColor(R.color.color_253444));
                        view_btn3.setBackgroundColor(getResources().getColor(R.color.color_253444));
                        view_btn1.setBackgroundColor(getResources().getColor(R.color.view_bg));
                        btn_first.setTextColor(getResources().getColor(R.color.white));
                        image_viceo_play.setImageResource(R.drawable.evening_bg_voice_play);
                    }
                    setVideoDate();
                    setMenuData();

                    handler.sendEmptyMessage(0);

                } else {
                    showErrorDialog("网络请求错误，请稍后再试！");
                }
            }

            @Override
            public void onAfter() {
                super.onAfter();
                closeLoadingDialog();
            }
        }
        OkHttpUtils.post().url(UrlConsts.APP_POWERED_UP)
                .addParams("version", appVersion)
                .addParams("platform", platformType)
                .addParams("loginType", loginType)
                .addParams("account", userName)
                .addParams("password", password)
                .addParams("deviceId", devicedId)
                .addParams("hisFirst", String.valueOf(1))
                .addParams("dayFirst", String.valueOf(1))
                .addParams("pushKey", pushKey)
                .build()
                .execute(new homeCallBack());

    }

    private void getData(HomeBean homeBean) {
        activityListEntities.clear();
        videoListEntities.clear();
        menuListEntities.clear();
        for (HomeBean.ActivityListEntity activityListEntity : homeBean.getActivityList()) {
            activityListEntities.add(activityListEntity);
        }
        for (HomeBean.VideoListEntity videoListEntity : homeBean.getVideoList()) {
            videoListEntities.add(videoListEntity);
        }
        if (homeBean.getMenuList() != null) {
            for (HomeBean.MenuListEntity menuListEntity : homeBean.getMenuList()) {
                menuListEntities.add(menuListEntity);
            }
        }

        if (mHomeBean.getCode().equalsIgnoreCase("0000")) {
            updateAPP(mHomeBean.getUpdateFlag(), mHomeBean.getupdateUrl());
            if (mHomeBean.getShowReddot() != null) {
                if (mHomeBean.getShowReddot().equals("1")) {
                    imag_menu_round.setVisibility(View.VISIBLE);
                } else {
                    imag_menu_round.setVisibility(View.GONE);
                }
            }

            dayTheme = mHomeBean.getDayTheme();
            initColor(dayTheme);
            setDaybg(dayTheme);
            if (dayTheme == 0) {
                image_viceo_play.setImageResource(R.drawable.whiteday_bg_voice_play);
                view_btn1.setBackgroundColor(getResources().getColor(R.color.m_view_bg_select));
                btn_first.setTextColor(getResources().getColor(R.color.black));
            } else if (dayTheme == 1) {
                view_btn2.setBackgroundColor(getResources().getColor(R.color.color_253444));
                view_btn3.setBackgroundColor(getResources().getColor(R.color.color_253444));
                view_btn1.setBackgroundColor(getResources().getColor(R.color.view_bg));
                btn_first.setTextColor(getResources().getColor(R.color.white));
                image_viceo_play.setImageResource(R.drawable.evening_bg_voice_play);
            }
            setVideoDate();
            setMenuData();
            application.setHomeBean(null);
            handler.sendEmptyMessage(0);

        }
    }

    private void getHistoryDate(String day) {
        mSize = 0;

        HashMap<String, String> params = new HashMap<>();
        params.put("dayIndex", day);
        params.put("account", loginAccount == null ? "" : loginAccount);
        showLoadingDialog();
        TaskExecutor.getInstance().execute(new PostRequestTask(params, HomedActivity.this, UrlConsts.USER_WATCH_HOISTORY) {
            @Override
            protected void handleResponse(String response) {
                ArrayList<VideoInfo> tmpList = new ArrayList<VideoInfo>();
                try {
                    JSONObject object = new JSONObject(response);
                    int code = object.getInt("code");
                    String msg = object.getString("message");
                    if (code == 0000) {
                        JSONArray videoArray = object.getJSONArray("videoBaseVOList");
                        if (videoArray != null && videoArray.length() > 0) {

                            for (int i = 0; i < videoArray.length(); i++) {
                                JSONObject jsonObject = videoArray.getJSONObject(i);
                                VideoInfo item = new VideoInfo();
                                item.setType(1);
                                item.setId(jsonObject.getString("vid"));
                                item.setVideoName(jsonObject.getString("videoName"));
                                item.setVideoDesc(jsonObject.getString("themeDesc"));
                                item.setVideoDesc(jsonObject.getString("videoDesc"));
                                item.setVideoPicUrl(jsonObject.getString("videoPicUrl"));
                                item.setVideoUrl(jsonObject.getString("videoUrl"));
                                item.setVideoTypeName(jsonObject.getString("themeName"));
                                item.setThemeVoiceUrl(jsonObject.getString("themeVoiceUrl"));
                                tmpList.add(item);
                            }
                        }
                        closeLoadingDialog();
//                        setvideoText(0);
//                        myVPAdapter.setVideoList(mList);
//                        myVPAdapter.notifyDataSetChanged();
                    } else {
                        throw new Exception(msg);
                    }
                    closeLoadingDialog();
                    handler.sendEmptyMessage(0);
//                    myVPAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    ToastUtils.showToast(HomedActivity.this, e.getMessage());
                } finally {
                    closeLoadingDialog();
                }

                mList.clear();
                mList.addAll(tmpList);
            }
        });
    }

    private int mSize;

    private void setVideoDate() {
        if (activityListEntities.size() > 0) {
            mSize = activityListEntities.size();
            for (int i = 0; i < activityListEntities.size(); i++) {
                VideoInfo videoInfo = new VideoInfo();
                videoInfo.setType(0);
                HomeBean.ActivityListEntity activityListEntity = activityListEntities.get(i);
                videoInfo.setId(activityListEntity.getVid() + "");
                videoInfo.setVideoTypeId(activityListEntity.getActivityType());
                videoInfo.setActivityType(activityListEntity.getActivityType());
                videoInfo.setActivityName(activityListEntity.getActivityName());
                videoInfo.setVideoDesc(activityListEntity.getVideoDesc());
                videoInfo.setVideoType(activityListEntity.getVideoType());
                videoInfo.setPicUrl(activityListEntity.getPicUrl());
                videoInfo.setPageUrl(activityListEntity.getPageUrl());
                mList.add(videoInfo);
            }
        }
        if (videoListEntities.size() > 0) {
            for (int i = 0; i < videoListEntities.size(); i++) {
                VideoInfo videoInfo2 = new VideoInfo();
                videoInfo2.setType(1);
                HomeBean.VideoListEntity videoListEntity = videoListEntities.get(i);
                videoInfo2.setId(videoListEntity.getVid() + "");
                videoInfo2.setVideoName(videoListEntity.getVideoName());
                videoInfo2.setVideoDesc(videoListEntity.getVideoDesc());
                videoInfo2.setVideoPicUrl(videoListEntity.getVideoPicUrl());
                videoInfo2.setVideoUrl(videoListEntity.getVideoUrl());
                videoInfo2.setVideoType(videoListEntity.getVideoType());
                videoInfo2.setVideoTypeName(videoListEntity.getThemeName());
                videoInfo2.setThemeVoiceUrl(videoListEntity.getThemeVoiceUrl());
                mList.add(videoInfo2);
            }
        }
    }

    private void setMenuData() {
        if (menuListEntities.size() > 0) {
            mMenuList.clear();
            for (int i = 0; i < menuListEntities.size(); i++) {
                Menubean menubean = new Menubean();
                HomeBean.MenuListEntity menuListEntity = menuListEntities.get(i);
                menubean.setMenuName(menuListEntity.getMenuName());
                menubean.setMenuPicUrl(menuListEntity.getMenuUrl());
                menubean.setMenuWebUrl(menuListEntity.getMenuLink());
                menubean.setMenuType(menuListEntity.getMenuType());
                menubean.setMenuId(menuListEntity.getMenuId());
                menubean.setShowReddot(menuListEntity.getShowReddot());
                menubean.setVideoType(menuListEntity.getVideoType());
                menubean.setVideoId(menuListEntity.getVideoId());
                mMenuList.add(menubean);
            }
            application.setMenubean(mMenuList);

            refeshMenuRound();
            adapter.notifyDataSetChanged();
        }
    }

    private void refeshMenuRound() {
        boolean isMenuMessage = false;
        if (mMenuList.size() > 0) {
            for (Menubean menubean : mMenuList) {
                if (menubean.getShowReddot() == 1) {
                    isMenuMessage = true;
                }
            }
        } else {
            isMenuMessage = false;
        }

        if (isMenuMessage) {
            imag_menu_round.setVisibility(View.VISIBLE);
        } else {
            imag_menu_round.setVisibility(View.GONE);
        }
    }

    /**
     * 视频详情
     *
     * @param position
     */
    private void setvideoText(int position) {

        if (mList.size() > 0) {
            if (mList.get(position).getType() == 0) {
                video_title.setText(mList.get(position).getActivityName());
                video_content.setText(mList.get(position).getVideoDesc());

            } else {
                bg_video.setImageResource(R.drawable.video_bg_img);
                video_title.setText(mList.get(position).getVideoName());
                video_content.setText(mList.get(position).getVideoDesc());
            }
            palyVoide(position);
        }
    }

    /**
     * 播放音频
     *
     * @param position
     */
    private void palyVoide(int position) {
        if (voicePlayer != null) {
            voicePlayer.release();
            voicePlayer = null;
            voicePlayer = new MediaPlayer();
        } else {
            voicePlayer = new MediaPlayer();
        }
        voicePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                if (voicePlayer != null && !isVoicePlay) {
                    voicePlayer.start();
                } else {
                    voicePlayer.pause();
                }
            }
        });
        try {
            String voiceURL = mList.get(position).getThemeVoiceUrl();
            if (voiceURL != null && voiceURL != "") {
                voicePlayer.setDataSource(voiceURL);
                voicePlayer.prepareAsync();
            }
        } catch (Exception ex) {
            Toast toast = Toast.makeText(HomedActivity.this, "Error Playing Sound:" + ex.toString(), Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    class menuListAdapter extends BaseAdapter {
        @Override
        public Object getItem(int position) {
            return mMenuList.get(position);
        }

        @Override
        public int getCount() {
            return mMenuList.size();
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final ViewHolder viewHolder;
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = View.inflate(context, R.layout.listview_item_menu, null);
                viewHolder.lay_menu_list = (LinearLayout) convertView.findViewById(R.id.lay_menu_list);
                viewHolder.img_menu_pic = (ImageView) convertView.findViewById(R.id.img_web_short);
                viewHolder.img_menu_mark = (ImageView) convertView.findViewById(R.id.imag_short_round);
                viewHolder.tv_menu_name = (TextView) convertView.findViewById(R.id.tv_web_short);

                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }

            final Menubean menubean = mMenuList.get(position);

            if (menubean.getShowReddot() == 1) {
                viewHolder.img_menu_mark.setVisibility(View.VISIBLE);
            } else {
                viewHolder.img_menu_mark.setVisibility(View.GONE);
            }
            viewHolder.lay_menu_list.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(voicePlayer.isPlaying()){
                        voicePlayer.pause();
                    }                    viewHolder.img_menu_mark.setVisibility(View.GONE);
                    if (mMenuList.get(position).getVideoType() != null) {
                        if (mMenuList.get(position).getVideoType().equals("0")) {
                            Intent intent = new Intent();
                            intent.putExtra("videoId", mMenuList.get(position).getVideoId());
                            intent.putExtra("menuId", mMenuList.get(position).getMenuId());
                            intent.setClass(HomedActivity.this, MenuVideodetailActivity.class);
                            startActivity(intent);
                        } else if (mMenuList.get(position).getVideoType().equals("1")) {
                            Intent intent = new Intent();
                            intent.putExtra("videoId", mMenuList.get(position).getVideoId());
                            intent.putExtra("menuId", mMenuList.get(position).getMenuId());
                            Log.e("wu", "  //// " + menubean.getMenuId());
                            intent.setClass(HomedActivity.this, MenuVideodetailActivity.class);
                            startActivity(intent);
                        }
                    } else {
                        Intent intent = new Intent();
                        intent.putExtra("activityName", mMenuList.get(position).getMenuName());
                        intent.putExtra("activityUrl", mMenuList.get(position).getMenuWebUrl());
                        intent.putExtra("menuId", mMenuList.get(position).getMenuId());
                        Log.e("wu", "  //// " + menubean.getMenuId());
                        intent.putExtra("showreddot", mMenuList.get(position).getShowReddot());
                        intent.setClass(HomedActivity.this, ActivityVideoWebActivirt.class);
                        startActivity(intent);
                    }

                    if (mMenuList.get(position).getShowReddot() == 1) {
                        mMenuList.get(position).setShowReddot(0);
                        application.setMenubean(mMenuList);
                    }
                    refeshMenuRound();
                    mMenu.close();
                }

            });

            VolleyImageUtils.displayImage(menubean.getMenuPicUrl(), viewHolder.img_menu_pic, HomedActivity.this);
            viewHolder.img_menu_mark.setImageResource(R.drawable.round_bg);
            viewHolder.tv_menu_name.setText(menubean.getMenuName());

            return convertView;
        }
    }

    class ViewHolder {
        LinearLayout lay_menu_list;
        //菜单图片
        ImageView img_menu_pic;
        //菜单标识
        ImageView img_menu_mark;
        //才到那名称
        TextView tv_menu_name;

    }

    /**
     * 用户第一次 点击back键时，提示用户‘再按一次返回键退出’
     * 第二次点击back键时将推出程序。
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            long secondtime = System.currentTimeMillis();
            if (secondtime - firstime > 3000) {
                ToastUtils.showToast(context, "再按一次返回键退出");
                firstime = System.currentTimeMillis();
                return true;
            } else {
                finish();
                System.exit(0);
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  //注意本行的FLAG设置
                startActivity(intent);
                finish();//关掉自己
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    private final int ACTIVITY_REGISTER = 1;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode) {
            case RESULT_OK:
                if (requestCode == ACTIVITY_REGISTER) {
                    if (selectBtn == 0) {
                        if (NetworkUtils.isNetworkAvailable(context)) {
                            sendRequest();
                        } else {
                            showErrorDialog("当前网络异常");
                        }
                    } else if (selectBtn == 1) {
                        if (NetworkUtils.isNetworkAvailable(context)) {
                            getHistoryDate("1");
                        } else {
                            showErrorDialog("当前网络异常");
                        }
                    } else if (selectBtn == 2) {
                        if (NetworkUtils.isNetworkAvailable(context)) {
                            getHistoryDate("2");
                        } else {
                            showErrorDialog("当前网络异常");
                        }
                    }
                }
                break;
            default:
                break;
        }
    }
}
